package cn.jdbc.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

//mysql jquery
public class Test03 {
    public static void main(String[] args) throws Exception{
//        加载驱动
        Class.forName("com.mysql.jdbc.Driver");
//        获取连接
        String url="jdbc:mysql://localhost:3306/test";
        String name="root";
        String password="root";
        Connection connection = DriverManager.getConnection(url, name,
                password);
//        建立陈述对象
        Statement statement = connection.createStatement();
//        建立查询
        ResultSet resultSet = statement.executeQuery("SELECT `id`,`username`,`password` FROM `table-user`;");
//        获取数据
        System.out.println("id\t  name\t\t  password");
        while (resultSet.next()){
            String j=resultSet.getString(2);
            long id = resultSet.getLong(1);
            String ps = resultSet.getString(3);

            System.out.println(id+"\t"+j+"\t\t"+ps);

        }
    }
}
